module tb_sBox();
  
  reg  [7:0] sbox_in;
  reg [31:0] sbox32_in;
  reg enc_dec;
  reg  [4:0] x, y;
  
  wire  [7:0] sbox_out;
  wire [31:0] sbox32_out;
  wire  [7:0] sbox_out_inv;
  wire  [7:0] sbox_ident;
  
  sBox_8 SBOX
  (
    .sbox_out ( sbox_out        ),
    .sbox_in  ( {x[3:0],y[3:0]} ),
    .enc_dec  ( enc_dec         )
  );
  
  sBox_8 SBOX_INV
  (
    .sbox_out ( sbox_out_inv    ),
    .sbox_in  ( {x[3:0],y[3:0]} ),
    .enc_dec  ( ~enc_dec        )
  );
  
  sBox_8 SBOX_INV_2
  (
    .sbox_out ( sbox_ident      ),
    .sbox_in  ( sbox_out        ),
    .enc_dec  ( ~enc_dec        )
  );
  
  sBox SBOX32
  (
    .sbox_out ( sbox32_out ),
    .sbox_in  ( sbox32_in  ),
    .enc_dec  ( enc_dec  )
  );
  
  initial
    begin
      sbox32_in = 32'hbe_e3_3d_19;
    end
  
  initial
    begin
      enc_dec = 1'b1;
      $display("S-Box:");
      for(x = 0; x < 16; x = x + 1)
        begin
          for(y = 0; y < 16; y = y + 1)
            begin
                #1 $write("%x ", sbox_out);
            end
          #1 $write("\n");
        end
      $display("\nInv S-Box:");
      for(x = 0; x < 16; x = x + 1)
        begin
          for(y = 0; y < 16; y = y + 1)
            begin
                #1 $write("%x ", sbox_out_inv);
            end
          #1 $write("\n");
        end
      $display("Ident:");
      for(x = 0; x < 16; x = x + 1)
        begin
          for(y = 0; y < 16; y = y + 1)
            begin
              #1;
              if(sbox_ident != {x[3:0], y[3:0]})
                begin
                  $display("ERROR! - %x != %x", sbox_ident, {x[3:0], y[3:0]});
                  $finish;
                end
              else
                #1 $write("%x ", sbox_ident);
            end
          #1 $write("\n");
        end
        $finish;    
    end
endmodule
